﻿using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using SuperSocket;
using SuperSocket.Command;
using System.Threading.Tasks;
using Serilog;
using Serilog.Events;

namespace GpsServer
{
    internal class Program
    {
        private static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
#if DEBUG
                .MinimumLevel.Debug()
                .WriteTo.Console()
#else
                .MinimumLevel.Information()
#endif
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Async(c => c.File("Logs/logs.log", outputTemplate: "{Timestamp:HH:mm} || {Level} || {SourceContext:l} || {Message} || {Exception} ||end {NewLine}"))
                .CreateLogger();

            var host = SuperSocketHostBuilder.Create<MyPackageInfo>()
               .UsePipelineFilterFactory<MyFilterFactory>()
               .ConfigureLogging(loggingBuilder =>
              {
                  loggingBuilder.AddConsole();
              })
               .UseSerilog()
              .ConfigureSuperSocket(options =>
              {
                  options.Name = "Echo Server";
                  options.Listeners = new ListenOptions[] {
                         new ListenOptions {
                            Ip = "Any",
                           Port = 4040
                         }
                  };
              })
              .UseSession<MySession>()
              .UseCommand<ProtocolNo, MyPackageInfo>((cmdOptions) =>
              {
                  cmdOptions.AddCommandAssembly(typeof(Program).Assembly);
              }).Build();
            await host.RunAsync();
        }
    }
}